package com.whiteape.book.model.gen;

import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;

import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.internal.DaoConfig;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;

import com.whiteape.book.utils.MapConverter;
import java.util.HashMap;

import com.whiteape.book.model.dto.SiteSourceCategoryBean;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/** 
 * DAO for table "SITE_SOURCE_CATEGORY_BEAN".
*/
public class SiteSourceCategoryBeanDao extends AbstractDao<SiteSourceCategoryBean, String> {

    public static final String TABLENAME = "SITE_SOURCE_CATEGORY_BEAN";

    /**
     * Properties of entity SiteSourceCategoryBean.<br/>
     * Can be used for QueryBuilder and for referencing column names.
     */
    public static class Properties {
        public final static Property SiteHostUrl = new Property(0, String.class, "siteHostUrl", false, "SITE_HOST_URL");
        public final static Property CategoryName = new Property(1, String.class, "categoryName", false, "CATEGORY_NAME");
        public final static Property CategoryUrl = new Property(2, String.class, "categoryUrl", true, "CATEGORY_URL");
        public final static Property VarMap = new Property(3, String.class, "varMap", false, "VAR_MAP");
    }

    private DaoSession daoSession;

    private final MapConverter varMapConverter = new MapConverter();

    public SiteSourceCategoryBeanDao(DaoConfig config) {
        super(config);
    }
    
    public SiteSourceCategoryBeanDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
        this.daoSession = daoSession;
    }

    /** Creates the underlying database table. */
    public static void createTable(Database db, boolean ifNotExists) {
        String constraint = ifNotExists? "IF NOT EXISTS ": "";
        db.execSQL("CREATE TABLE " + constraint + "\"SITE_SOURCE_CATEGORY_BEAN\" (" + //
                "\"SITE_HOST_URL\" TEXT," + // 0: siteHostUrl
                "\"CATEGORY_NAME\" TEXT," + // 1: categoryName
                "\"CATEGORY_URL\" TEXT PRIMARY KEY NOT NULL ," + // 2: categoryUrl
                "\"VAR_MAP\" TEXT);"); // 3: varMap
        // Add Indexes
        db.execSQL("CREATE INDEX " + constraint + "IDX_SITE_SOURCE_CATEGORY_BEAN_SITE_HOST_URL ON \"SITE_SOURCE_CATEGORY_BEAN\"" +
                " (\"SITE_HOST_URL\" ASC);");
    }

    /** Drops the underlying database table. */
    public static void dropTable(Database db, boolean ifExists) {
        String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"SITE_SOURCE_CATEGORY_BEAN\"";
        db.execSQL(sql);
    }

    @Override
    protected final void bindValues(DatabaseStatement stmt, SiteSourceCategoryBean entity) {
        stmt.clearBindings();
 
        String siteHostUrl = entity.getSiteHostUrl();
        if (siteHostUrl != null) {
            stmt.bindString(1, siteHostUrl);
        }
 
        String categoryName = entity.getCategoryName();
        if (categoryName != null) {
            stmt.bindString(2, categoryName);
        }
 
        String categoryUrl = entity.getCategoryUrl();
        if (categoryUrl != null) {
            stmt.bindString(3, categoryUrl);
        }
 
        HashMap varMap = entity.getVarMap();
        if (varMap != null) {
            stmt.bindString(4, varMapConverter.convertToDatabaseValue(varMap));
        }
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, SiteSourceCategoryBean entity) {
        stmt.clearBindings();
 
        String siteHostUrl = entity.getSiteHostUrl();
        if (siteHostUrl != null) {
            stmt.bindString(1, siteHostUrl);
        }
 
        String categoryName = entity.getCategoryName();
        if (categoryName != null) {
            stmt.bindString(2, categoryName);
        }
 
        String categoryUrl = entity.getCategoryUrl();
        if (categoryUrl != null) {
            stmt.bindString(3, categoryUrl);
        }
 
        HashMap varMap = entity.getVarMap();
        if (varMap != null) {
            stmt.bindString(4, varMapConverter.convertToDatabaseValue(varMap));
        }
    }

    @Override
    protected final void attachEntity(SiteSourceCategoryBean entity) {
        super.attachEntity(entity);
        entity.__setDaoSession(daoSession);
    }

    @Override
    public String readKey(Cursor cursor, int offset) {
        return cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2);
    }    

    @Override
    public SiteSourceCategoryBean readEntity(Cursor cursor, int offset) {
        SiteSourceCategoryBean entity = new SiteSourceCategoryBean( //
            cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0), // siteHostUrl
            cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // categoryName
            cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // categoryUrl
            cursor.isNull(offset + 3) ? null : varMapConverter.convertToEntityProperty(cursor.getString(offset + 3)) // varMap
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, SiteSourceCategoryBean entity, int offset) {
        entity.setSiteHostUrl(cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0));
        entity.setCategoryName(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
        entity.setCategoryUrl(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
        entity.setVarMap(cursor.isNull(offset + 3) ? null : varMapConverter.convertToEntityProperty(cursor.getString(offset + 3)));
     }
    
    @Override
    protected final String updateKeyAfterInsert(SiteSourceCategoryBean entity, long rowId) {
        return entity.getCategoryUrl();
    }
    
    @Override
    public String getKey(SiteSourceCategoryBean entity) {
        if(entity != null) {
            return entity.getCategoryUrl();
        } else {
            return null;
        }
    }

    @Override
    public boolean hasKey(SiteSourceCategoryBean entity) {
        return entity.getCategoryUrl() != null;
    }

    @Override
    protected final boolean isEntityUpdateable() {
        return true;
    }
    
}
